package com.aolong.archives.core.sysmanage.dao.impl;

import java.util.HashMap;
import java.util.Map;

import com.aolong.archives.core.sysmanage.dao.IRoleDao;
import com.aolong.archives.core.sysmanage.entity.RoleEntity;
import com.rock.platform.dao.BaseDao;
import com.rock.platform.entity.ActionParamsEntity;
import com.rock.platform.entity.PageEntity;

public class RoleDao extends BaseDao implements IRoleDao {

	public PageEntity findAll(ActionParamsEntity actionParams) {
		
		String strSql = "select r.* from TSM_Role r";
		actionParams.replaceField("typeDesc", "type").replaceField("statusDesc", "status").addSort("roleCode");
		return super.getPageEntity(strSql, actionParams, RoleEntity.class);
	}

	public PageEntity findByUserId(String userId,ActionParamsEntity actionParams) {
		
		String strSql = "select r.* from TSM_Role r "
					  + " where r.roleId in (select roleId where TSM_RoleUser where userId = :userId) "
					  + " order by roleCode";
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("userId", userId);
		actionParams.addSort("roleCode");
		return super.getPageEntity(strSql, actionParams, RoleEntity.class, params);
	}
}
